<template>
    <div class="blog-home">
        <section class="profile-section">
            <img class="avatar" src="@/assets/vite.svg" alt="头像">
            <div class="profile-info">
                <h2>于君的博客</h2>
                <p>前端开发者 | 热爱技术与生活</p>
                <p>记录学习、生活与成长</p>
            </div>
        </section>
        <div class="main-layout">
            <div class="main-content">
                <!-- 轮播图 -->
                <el-carousel height="200px" class="carousel">
                    <el-carousel-item v-for="(item, idx) in banners" :key="idx">
                        <img :src="item.img" :alt="item.title" class="carousel-img" />
                        <div class="carousel-title">{{ item.title }}</div>
                    </el-carousel-item>
                </el-carousel>
                <!-- 搜索框 -->
                <el-input v-model="search" placeholder="搜索文章..." clearable class="search-input" />
                <!-- 最新文章列表 -->
                <section class="posts-section">
                    <h3>最新文章</h3>
                    <div class="post-list">
                        <div class="post-card" v-for="post in filteredPosts" :key="post.id">
                            <h4>{{ post.title }}</h4>
                            <p class="post-meta">{{ post.date }} · {{ post.category }}</p>
                            <p class="post-desc">{{ post.desc }}</p>
                            <el-button type="primary" size="small">阅读全文</el-button>
                        </div>
                    </div>
                </section>
                <section class="about-section">
                    <h3>关于我</h3>
                    <p>欢迎来到我的个人博客，这里分享前端开发、生活随笔与成长感悟。</p>
                </section>
            </div>
            <div class="sidebar">
                <!-- 统计信息 -->
                <div class="stat-card">
                    <h4>博客统计</h4>
                    <div class="stat-list">
                        <div class="stat-item">
                            <div class="stat-icon stat-article"><i class="el-icon-document"></i></div>
                            <div class="stat-info">
                                <div class="stat-num">{{ posts.length }}</div>
                                <div class="stat-label">文章总数</div>
                            </div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-icon stat-read"><i class="el-icon-view"></i></div>
                            <div class="stat-info">
                                <div class="stat-num">{{ todayRead }}</div>
                                <div class="stat-label">今日阅读</div>
                            </div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-icon stat-comment"><i class="el-icon-chat-dot-square"></i></div>
                            <div class="stat-info">
                                <div class="stat-num">{{ commentCount }}</div>
                                <div class="stat-label">评论数</div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- 日历 -->
                <div class="calendar-card">
                    <div class="calendar-title">
                        <h4>日历</h4>
                        <div class="calendar-divider"></div>
                    </div>
                    <el-calendar v-model="calendarDate" class="pretty-calendar">
                        <template #dateCell="{ data }">
                            <div
                                :class="[
                                    'custom-date-cell',
                                    data.isSelected ? 'is-selected' : '',
                                    data.isToday ? 'is-today' : ''
                                ]"
                            >
                                {{ data.day }}
                            </div>
                        </template>
                    </el-calendar>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, computed } from 'vue';
const posts = ref([
    { id: 1, title: 'Vue3 组件通信全解', date: '2024-05-01', category: '前端', desc: '详解 Vue3 组件间的各种通信方式及最佳实践。' },
    { id: 2, title: '我的2024年学习计划', date: '2024-04-20', category: '生活', desc: '新一年如何高效学习与成长，目标与方法分享。' },
    { id: 3, title: 'CSS 动画实用技巧', date: '2024-04-10', category: '前端', desc: '常用 CSS 动画效果及其实现思路。' },
]);
const banners = ref([
    { img: 'https://picsum.photos/800/200?random=1', title: '欢迎访问于君的博客' },
    { img: 'https://picsum.photos/800/200?random=2', title: '前端技术分享' },
    { img: 'https://picsum.photos/800/200?random=3', title: '生活与成长' },
]);
const search = ref('');
const filteredPosts = computed(() => {
    if (!search.value) return posts.value;
    return posts.value.filter(post =>
        post.title.includes(search.value) ||
        post.desc.includes(search.value) ||
        post.category.includes(search.value)
    );
});
const todayRead = ref(23); // 假数据
const commentCount = ref(5); // 假数据
const calendarDate = ref(new Date());
</script>

<style scoped>
.blog-home {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 16px;
    background: var(--el-bg-color);
    color: var(--el-text-color-primary);
}
.profile-section {
    display: flex;
    align-items: center;
    margin-bottom: 32px;
    background: var(--el-bg-color);
    border-radius: 12px;
    box-shadow: var(--el-box-shadow-light);
    padding: 24px;
    border: 1px solid var(--el-border-color);
}
.avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin-right: 24px;
    border: 2px solid var(--el-color-primary);
}
.profile-info h2 {
    margin: 0 0 8px 0;
    font-size: 2rem;
    color: var(--el-color-primary);
}
.profile-info p {
    margin: 0 0 4px 0;
    color: var(--el-text-color-secondary);
}
.main-layout {
    display: flex;
    gap: 32px;
}
.main-content {
    flex: 1 1 0%;
    min-width: 0;
}
.carousel {
    margin-bottom: 24px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--el-box-shadow-light);
    background: var(--el-bg-color);
}
.carousel-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}
.carousel-title {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.3);
    color: #fff;
    padding: 8px 16px;
    font-size: 1.2rem;
}
.search-input {
    margin-bottom: 20px;
    width: 100%;
}
.posts-section {
    margin-bottom: 32px;
}
.post-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.post-card {
    background: var(--el-bg-color);
    border-radius: 8px;
    box-shadow: var(--el-box-shadow-light);
    padding: 16px 20px;
    transition: box-shadow 0.2s;
    border: 1px solid var(--el-border-color);
    color: var(--el-text-color-primary);
}
.post-card:hover {
    box-shadow: var(--el-box-shadow-dark);
}
.post-meta {
    font-size: 0.9rem;
    color: var(--el-text-color-secondary);
    margin-bottom: 8px;
}
.post-desc {
    color: var(--el-text-color-regular);
    margin-bottom: 8px;
}
.about-section {
    background: var(--el-fill-color-light);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: var(--el-text-color-secondary);
}
.sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.stat-card {
    background: var(--el-bg-color);
    border-radius: 16px;
    box-shadow: var(--el-box-shadow-light);
    padding: 28px 20px 20px 20px;
    margin-bottom: 8px;
    border: 1px solid var(--el-border-color);
}
.stat-card h4 {
    margin-bottom: 18px;
    font-size: 1.2rem;
    color: var(--el-color-primary);
    letter-spacing: 1px;
    text-align: center;
}
.stat-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.stat-item {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--el-fill-color-light);
    border-radius: 10px;
    box-shadow: var(--el-box-shadow-light);
    padding: 12px 16px;
    transition: box-shadow 0.2s;
    border: 1px solid var(--el-border-color);
}
.stat-item:hover {
    box-shadow: var(--el-box-shadow-dark);
}
.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
}
.stat-article {
    background: linear-gradient(135deg, #7dd3fc 0%, #38bdf8 100%);
}
.stat-read {
    background: linear-gradient(135deg, #a7f3d0 0%, #34d399 100%);
}
.stat-comment {
    background: linear-gradient(135deg, #fca5a5 0%, #f87171 100%);
}
.stat-num {
    font-size: 2rem;
    font-weight: bold;
    color: var(--el-text-color-primary);
    line-height: 1;
}
.stat-label {
    font-size: 0.95rem;
    color: var(--el-text-color-secondary);
}
.calendar-card {
    background: var(--el-bg-color);
    border-radius: 16px;
    box-shadow: var(--el-box-shadow-light);
    padding: 18px 12px 12px 12px;
    border: 1px solid var(--el-border-color);
}
.calendar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.calendar-title h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--el-color-primary);
}
.calendar-divider {
    flex: 1;
    height: 1px;
    background: var(--el-border-color);
    margin-left: 12px;
}
.pretty-calendar {
    background: var(--el-bg-color);
    border-radius: 18px;
    box-shadow: var(--el-box-shadow-light);
    padding: 10px 4px 4px 4px;
    border: 1px solid var(--el-border-color);
}
.custom-date-cell {
    width: 32px;
    height: 32px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    font-size: 1rem;
    font-weight: 500;
}
.custom-date-cell.is-today {
    background: linear-gradient(135deg, #7dd3fc 0%, #38bdf8 100%);
    color: #fff;
}
.custom-date-cell.is-selected {
    background: var(--el-color-primary);
    color: #fff;
}
.pretty-calendar .el-calendar__header {
    border-bottom: none;
    margin-bottom: 8px;
}
.pretty-calendar .el-calendar__body {
    padding: 0;
}
.pretty-calendar .el-calendar-table th {
    font-weight: bold;
    color: var(--el-color-primary);
    background: none;
}
.pretty-calendar .el-calendar-table td {
    background: none;
    border: none;
}
.stat-card ul, .stat-card li {
    display: none;
}
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        flex-direction: row;
        gap: 16px;
    }
}
</style>